import { NoSkinCellRenderer } from "../common/item/NoSkinCellRenderer";
import { Cache } from "../../cache/Cache";
import { TOpenRechargeGiftBag } from "../../../../Message/Db/Tables/TOpenRechargeGiftBag";
import { ItemData } from "../../resource/info/ItemData";
import { DataEvent } from "../../events/DataEvent";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { ObjCreate } from "../common/ObjCreate";
import { BaseItem } from "../common/BaseItem";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GBitmap } from "../../../../com/mui/controls/GBitmap";
import { GButton } from "../../../../com/mui/controls/GButton";
import { NewYearCountGiftBagCache } from "../../cache/NewYearCountGiftBagCache";
type int = number;
//class NewYearCountGiftBagRenderer
    
    export  class NewYearCountGiftBagRenderer extends NoSkinCellRenderer
    {
        constructor()
        {
            super();
            this._cache = Cache.instance.newYearCount;
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (typeof arg1 === "topenrechargegiftbag") 
            {
                this._vo = arg1 as TOpenRechargeGiftBag;
                this._index = this._cache.data.indexOf(this._vo) + 1;
                this._baseItem.itemData = new ItemData(this._vo.itemCode);
                this.setTitle();
            }
            return;
        }

        /* internal  */onUpdateHandler(arg1: DataEvent): void
        {
            if (!this._vo) 
            {
                return;
            }
            this._getBtn.label = Language.getString(20146);
            if (this._cache.hadGetCodes.indexOf(this._vo.code) != -1) 
            {
                this._getBtn.label = Language.getString(28783);
                this._getBtn.enabled = false;
                return;
            }
            if (this._index > this._cache.day) 
            {
                this._getBtn.label = Language.getString(28784);
                this._getBtn.enabled = false;
                if (!this._cache.hasFind) 
                {
                    Cache.instance.newYearCount.hasFind = true;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.NewYearItemRendererSelect, {"code": this._vo.itemCode, "index":(this._index - 1)}));
                }
                return;
            }
            var loc1=this._cache.getAllRecharge(this._index, this._vo.target);
            if (loc1 >= this._vo.target) 
            {
                this._getBtn.enabled = true;
                if (this._index == this._cache.data.length) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.NewYearItemRendererSelect, {"code": this._vo.itemCode, "index":(this._index - 1)}));
                }
            }
            else if (!this._cache.hasFind) 
            {
                Cache.instance.newYearCount.hasFind = true;
                Dispatcher.dispatchEvent(new DataEvent(EventName.NewYearItemRendererSelect, {"code": this._vo.itemCode, "index":(this._index - 1)}));
            }
            if (this.selected) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.NewYearCountGiftBagHasFindItem, {"cur": this._cache.getAllRecharge(this._index, this._vo.target), "sum": this._vo.target}));
            }
            return;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._vo) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.NewYearGetDayRechargeGiftBag, this._vo.code));
            }
            return;
        }

        /* internal  */setTitle(): void
        {
            if (this._loader && this._vo) 
            {
                this._title.bitmapData = GlobalClass.getBitmapData("NewYearCountGiftBagDay_" + this._index);
            }
            return;
        }

        /* internal  */onLoadResHandler(): void
        {
            this._loader = true;
            this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.NewYearCountGiftBagItemBg);
            this._arrow.bitmapData = GlobalClass.getBitmapData(ImagesConst.NewYearCountGiftBagArrow);
            this.setTitle();
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (arg1 && this._vo) 
            {
                this.addChildAt(this._bg, 0);
                this.addChild(this._arrow);
                Dispatcher.dispatchEvent(new DataEvent(EventName.NewYearCountGiftBagHasFindItem, {"cur": this._cache.getAllRecharge(this._index, this._vo.target), "sum": this._vo.target}));
            }
            else 
            {
                DisplayUtil.removeMe(this._bg);
                DisplayUtil.removeMe(this._arrow);
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._bg = ObjCreate.createGBitmap("", 0, 0);
            this._arrow = ObjCreate.createGBitmap("", 38, 145);
            ObjCreate.createBg(14, 32, 64, 64, this, ImagesConst.PackItemBg);
            this._title = ObjCreate.createGBitmap("", 19, 10, this);
            this._baseItem = new BaseItem();
            this._baseItem.isDragAble = false;
            this._baseItem.isDropAble = false;
            ObjCreate.setObjAttri(this._baseItem, 16, 34, 60, 60, this);
            this._getBtn = ObjCreate.createGButton(Language.getString(20146), 19, 105, 52, 26, this, "ButtonRed");
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            this._getBtn.enabled = false;
            Dispatcher.addEventListener(EventName.NewYearItemRendererUpdate, this.onUpdateHandler);
            LoaderHelp.addResCallBack(ResFileConst.newYearCountGiftBag, this.onLoadResHandler);
            return;
        }

        /* internal */ /* var */_bg: GBitmap;

        /* internal */ /* var */_arrow: GBitmap;

        /* internal */ /* var */_title: GBitmap;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_index: int;

        /* internal */ /* var */_cache: NewYearCountGiftBagCache;

        /* internal */ /* var */_vo: TOpenRechargeGiftBag;

        /* internal */ /* var */_loader: Boolean;
    }
